<%@ codepage=65001%>
<!-- #include file="conn.asp" -->
<!--#include file="UpLoad_Class.asp"-->
<%
Session.CodePage=65001
Response.Charset="utf-8"

sType = request("sType")

if sType = "add" then
	'wangdianName = request("wangdianName")
	'wangdianAddress = request("wangdianAddress")
	'wangdianAddressLng = request("wangdianAddressLng")
	'wangdianAddressLat = request("wangdianAddressLat")
	'province = request("province")
	'city = request("city")
	'district = request("district")
	'saleAreaId = request("saleAreaId")
	'wangdianAreaOwen = request("wangdianAreaOwen")
	'wangdianfuzeren = request("wangdianfuzeren")
	'wdfzrTel = request("wdfzrTel")
	'wangdianyewuren = request("wangdianyewuren")
	'wdywrTel = request("wdywrTel")
	'saleId = request("saleId")
	'wangdianPhoto = request("wangdianPhoto")
	'wangdianOwen = request("wangdianOwen")
	'beizhu = request("beizhu")
	
	dim upload
	set upload = new AnUpLoad
	upload.Charset="UTF-8"
	upload.Exe = "jpg|bmp|jpeg|gif|png"
	upload.MaxSize = 2 * 1024 * 1024     '设置最大上传限制
	'upload.SingleSize=500*1024          '设置单文件最大上传限制为500KB,按字节计；默认为不限制
	upload.GetData()
	'upload.CodePage = 65001
	
	
	saleId=0
	saleAreaId = 0
	city = 0
	district = 0
	
	if (IsEmpty(replace(upload.forms("id"),"'","")) or replace(upload.forms("id"),"'","")="" ) then
		id=0
	else
		id=cint(replace(upload.forms("id"),"'",""))
	end if
	'city = replace(upload.forms("city"),"'","")
	'district = replace(upload.forms("district"),"'","")
	wangdianName = replace(upload.forms("wangdianName"),"'","")
	wangdianAddress = replace(upload.forms("wangdianAddress"),"'","")
	wangdianAddressLng = replace(upload.forms("wangdianAddressLng"),"'","")
	wangdianAddressLat = replace(upload.forms("wangdianAddressLat"),"'","")
	province = replace(upload.forms("province"),"'","")
	wangdianAreaOwen = replace(upload.forms("wangdianAreaOwen"),"'","")
	wangdianfuzeren = replace(upload.forms("wangdianfuzeren"),"'","")
	wdfzrTel = replace(upload.forms("wdfzrTel"),"'","")
	wangdianyewuren = replace(upload.forms("wangdianyewuren"),"'","")
	wdywrTel = replace(upload.forms("wdywrTel"),"'","")
	wangdianOwen = replace(upload.forms("wangdianOwen"),"'","")
	beizhu = replace(upload.forms("beizhu"),"'","")
	'response.Write ",,,in ,,,, wangdianName=" & wangdianName & ",,,,,,wangdianAddress=" & wangdianAddress & ",,,,,,province=" & province & ",,,,,,wangdianAreaOwen=" & wangdianAreaOwen & ",,,,,,wangdianOwen=" & wangdianOwen
	if wangdianName <> "" then
		if upload.ErrorID>0 then 
			'response.Write upload.Description
			response.Write "{success:false,msg:1}"
		else
		dim savpath,sFileName,strResult,stateFile
			stateFile = 1
			for each i in upload.files(-1)
				set file = upload.files(i)
				if not(file is nothing) then
					stateFile = 0
				end if
			next
			
			if stateFile = 0 then
				
				for each f in upload.files(-1)
					dim file
					set file = upload.files(f)
	'				filename0=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)
	'				filename=filename0 & fileEXT
	'				sFileName= filename0 & fileEXT
					savepath = "upfile/"
					if not(file is nothing) then
						result = file.saveToFile(savepath,0,true)
						sFileName = savepath&""&file.filename
						
						if result then
							strResult = 0
								if id>0 then    'update
									sql="update wangdian set wangdianName='"&wangdianName&"',wangdianAddress='"&wangdianAddress&"',wangdianAddressLng='"& wangdianAddressLng &"',wangdianAddressLat='"& wangdianAddressLat &"',province='"&province&"',city='"&city&"',district='"&district&"',saleAreaId='"&saleAreaId&"',wangdianAreaOwen='"&wangdianAreaOwen&"',wangdianfuzeren='"&wangdianfuzeren&"',wdfzrTel='"&wdfzrTel&"',wangdianyewuren='"&wangdianyewuren&"',wdywrTel='"&wdywrTel&"',saleId='"&saleId&"',wangdianPhoto='"&sFileName&"',wangdianOwen='"&wangdianOwen&"',beizhu='"&beizhu&"' where id="&id
									conn.execute(sql)
									if err.number=0 then
										strResult = 3
									else
										strResult = 4
									end if
								else
									sql="insert into wangdian ([wangdianName],[wangdianAddress],[wangdianAddressLng],[wangdianAddressLat],[province],[city],[district],[saleAreaId],[wangdianAreaOwen],[wangdianfuzeren],[wdfzrTel],[wangdianyewuren],[wdywrTel],[saleId],[wangdianPhoto],[wangdianOwen],[beizhu]) values ('"&wangdianName&"','"&wangdianAddress&"','"&wangdianAddressLng&"','"&wangdianAddressLat&"','"&province&"','"&city&"','"&district&"','"&saleAreaId&"','"&wangdianAreaOwen&"','"&wangdianfuzeren&"','"&wdfzrTel&"','"&wangdianyewuren&"','"&wdywrTel&"','"&saleId&"','"&sFileName&"','"&wangdianOwen&"','"&beizhu&"')"
									'response.Write sql
									conn.execute(sql)
									if err.number=0 then
										strResult = 0
									else
										strResult = 1
									end if
								end if
						else
							strResult = 1
							exit for
						end if
					end if
					set file = nothing
					set rs = nothing
				next
			else
				strResult = 0
				if id>0 then    'update
					sql="update wangdian set wangdianName='"&wangdianName&"',wangdianAddress='"&wangdianAddress&"',wangdianAddressLng='"& wangdianAddressLng &"',wangdianAddressLat='"& wangdianAddressLat &"',province='"&province&"',city='"&city&"',district='"&district&"',saleAreaId='"&saleAreaId&"',wangdianAreaOwen='"&wangdianAreaOwen&"',wangdianfuzeren='"&wangdianfuzeren&"',wdfzrTel='"&wdfzrTel&"',wangdianyewuren='"&wangdianyewuren&"',wdywrTel='"&wdywrTel&"',saleId='"&saleId&"',wangdianOwen='"&wangdianOwen&"',beizhu='"&beizhu&"' where id="&id
					conn.execute(sql)
					if err.number=0 then
						strResult = 3
					else
						strResult = 4
					end if
				else
					sql="insert into wangdian ([wangdianName],[wangdianAddress],[wangdianAddressLng],[wangdianAddressLat],[province],[city],[district],[saleAreaId],[wangdianAreaOwen],[wangdianfuzeren],[wdfzrTel],[wangdianyewuren],[wdywrTel],[saleId],[wangdianPhoto],[wangdianOwen],[beizhu]) values ('"&wangdianName&"','"&wangdianAddress&"','"&wangdianAddressLng&"','"&wangdianAddressLat&"','"&province&"','"&city&"','"&district&"','"&saleAreaId&"','"&wangdianAreaOwen&"','"&wangdianfuzeren&"','"&wdfzrTel&"','"&wangdianyewuren&"','"&wdywrTel&"','"&saleId&"','"&sFileName&"','"&wangdianOwen&"','"&beizhu&"')"
					'response.Write sql
					conn.execute(sql)
					if err.number=0 then
						strResult = 0
					else
						strResult = 1
					end if
				end if
			end if
			response.Write "{success:true,msg:"&strResult&"}"
		end if
	else
		response.Write "{success:true,msg:1}"
	end if
	
	
elseif sType = "del" then
	'arrvalue=split(id,",")
'    for i=0 to ubound(arrvalue)
'      	on error resume next
'	  	sql="delete from wangdian where id=" & arrvalue(i)
'		conn.execute(sql)
'    next
	sql="delete from wangdian where id=" & cint(request("id"))
	conn.execute(sql)
else
end if


set upload = nothing
conn.close
%>